package com.alexjavi.eneagrama.itemsDrawer;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.TextView;

import com.actionbar.MiBaseActivity;
import com.witejavi.eneagrama.R;
import com.alexjavi.juegos.Peliculas;

public class Cursos extends MiBaseActivity {

	private final static String url = "http://www.isabelsalama.com/?q=Formacion-Eneagrama";
	
	private WebView myWebView;
//	private ProgressBar pBar; 
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		activarActionBar(true);
		
		//Lanzar AlertDialog
		AlertDialog.Builder ventanaEmergente = new AlertDialog.Builder(Cursos.this);
        // Creamos su vista, aprovechando un layout existente
        View vistaVentanaEmergente = LayoutInflater.from(getApplicationContext()).inflate(R.layout.mapas_alert_dialog, null);
        Button boton = (Button) vistaVentanaEmergente.findViewById(R.id.ButtonNombreEstilo);
        boton.setText("Descuento Premium");
        TextView texto = (TextView) vistaVentanaEmergente.findViewById(R.id.TextViewDescripcion);
        texto.setText(R.string.descuento_cursos);
		
        ventanaEmergente.setPositiveButton("OK", new  DialogInterface.OnClickListener() { // si le das al aceptar
          	public void onClick(DialogInterface dialog, int whichButton) {
          	}
        });
        
        ventanaEmergente.setView(vistaVentanaEmergente);
        ventanaEmergente.show();
		
		cargarURL(url);
		
	}
	
	private void cargarURL(String url) {
		
//		pBar = (ProgressBar) findViewById(R.id.activity_bar);
//		pBar.setMax(100);
//		pBar.getProgressDrawable().setColorFilter(Color.parseColor("#86B404"), Mode.SRC_IN);
		
		myWebView = (WebView) findViewById(R.id.webViewAcercaDe);
		
		myWebView.getSettings().setJavaScriptEnabled(true);          
		
		myWebView.setWebViewClient(new WebViewClient() {
			public boolean shouldOverrideUrlLoading(WebView view, String url) {
				 view.loadUrl(url);
		         return false;
		    }
			
			public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
	         }

	         public void onPageStarted(WebView view, String url, Bitmap favicon){
//	             pBar.setVisibility(View.VISIBLE);
	         }

           public void onPageFinished(WebView view, String url) {
//           		pBar.setVisibility(View.GONE);
			}
		}); 
		
		myWebView.setWebChromeClient(new WebChromeClient(){

	         public void onProgressChanged(WebView view, int progress) {
	        	
//                 pBar.setProgress(progress);
	         }
		});

		myWebView.getSettings().setSupportZoom(true);
		myWebView.getSettings().setBuiltInZoomControls(true); 
		
		myWebView.getSettings().setLoadWithOverviewMode(true);
		myWebView.getSettings().setUseWideViewPort(true);				
		myWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
		
		myWebView.loadUrl(url);
	}

	@Override
	protected int getLayoutResource() {
		return R.layout.cursos;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case android.R.id.home:
			finish();
			return true;
		}

		return super.onOptionsItemSelected(item);
	}

}